// 60 =

#include <algorithm>
#include <cstdio>
constexpr int MaxN = 1e5 + 5;
constexpr int MaxM = 1e1 + 5;
int n, m, q;
int c[MaxN];
int near[MaxM];
int pre[MaxN][MaxM];
long long dp[MaxN];
long long p[MaxN][MaxM];
long long su[MaxN][MaxM];
long long getValue(int l, int r, int color)
{
    return su[r][color] - su[l - 1][color];
}
int main()
{
    freopen("paint.in", "r", stdin);
    freopen("paint.out", "w", stdout);
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &c[i]);
        for (int j = 1; j <= m; j++)
        {
            pre[i][j] = near[j];
        }
        near[c[i]] = i;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            scanf("%lld", &p[i][j]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            su[i][j] = su[i - 1][j];
            su[i][j] += p[i][j];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        dp[i] = std::max(dp[i - 1] + p[i][c[i]], pre[i][c[i]] == 0
                                                     ? -0x7f7f'7f7f'7f7f'7f7f
                                                     : dp[pre[i][c[i]]] + getValue(pre[i][c[i]] + 1, i, c[i]));
    }
    printf("%lld\n", dp[n]);
    long long lastAnswer = dp[n];
    for (int i = 1; i <= q; i++)
    {
        int op;
        scanf("%d", &op);
        if (op == 1)
        {
            int x, y;
            scanf("%d%d", &x, &y);
            x ^= lastAnswer;
            y ^= lastAnswer;
            c[x] = y;
        }
        if (op == 2)
        {
            int l, r;
            scanf("%d%d", &l, &r);
            l ^= lastAnswer;
            r ^= lastAnswer;
            for (int j = 1; j <= m; j++)
            {
                near[j] = 0;
            }
            for (int j = l; j <= r; j++)
            {
                for (int k = 1; k <= m; k++)
                {
                    pre[j][k] = near[k];
                }
                near[c[j]] = j;
            }
            for (int j = l; j <= r; j++)
            {
                dp[j] = std::max((j - 1 < l ? 0 : dp[j - 1]) + p[j][c[j]],
                                 pre[j][c[j]] < l ? -0x7f7f'7f7f'7f7f'7f7f
                                                  : dp[pre[j][c[j]]] + getValue(pre[j][c[j]] + 1, j, c[j]));
            }
            printf("%lld\n", dp[r]);
            lastAnswer = dp[r];
        }
    }
    return 0;
}
